package com.foxhorse.androidpractice.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.foxhorse.androidpractice.R
import com.foxhorse.androidpractice.entity.KotlinEntity
import kotlinx.android.synthetic.main.item_listview_kotlin_listview_activity.view.*

/**
 * Created by fanyang on 2017/6/14.
 */
class KotlinListviewAdapter(private val list: List<KotlinEntity>, private val context: Context) : BaseAdapter() {
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val viewHolder: ViewHolder
        val view: View
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_listview_kotlin_listview_activity, parent, false)
            viewHolder = ViewHolder(view)
            view.tag = viewHolder
        } else {
            view = convertView
            viewHolder = view.tag as ViewHolder
        }
        viewHolder.des.setText(list.get(position).des)
        return view
    }

    override fun getItem(position: Int): Any {
        return list.get(position)
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return list.size
    }

    class ViewHolder(view: View) {
        val des = view.tv_des
    }
}